package com.adb.ww2.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import com.adb.ww2.Log;

public class DetailViewFragment extends Fragment{
	
	public static final String TAG = DetailViewFragment.class.getCanonicalName();
	
	/**
	 * Create Instance of DetailsView Fragment Activity
	 * 
	 */
	public static DetailViewFragment newInstance(int Index){
		
		Log.debug(TAG,"Get Instance of DetailViewFragment");
		DetailViewFragment mDetailFragment = new DetailViewFragment();
		// Supply index input as an argument.
        Bundle args = new Bundle();
        args.putInt("index", Index);
        mDetailFragment.setArguments(args);
		return mDetailFragment;
	}
	
	/**
	 * get Argument from Fragment Bundle 
	 */
	public int getShowIndex(){
		
		return getArguments().getInt("index",0);
	}
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		Log.debug(TAG,"onCreateView callback " + TAG);
		
		if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }
		
		//Take Scroll view 
		ScrollView scoller = new ScrollView(getActivity());
		//Take Text view add inside ScrollView
		TextView mTextView = new TextView(getActivity());
		int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
	                4, getActivity().getResources().getDisplayMetrics());
		mTextView.setPadding(padding, padding, padding, padding);
		Log.debug(TAG,"onCreateView callback " + TAG + " Position "+ getShowIndex());
		mTextView.setText(com.adb.ww2.Constant.DIALOGUE[getShowIndex()]);
		scoller.addView(mTextView);
		
		return scoller;
	}
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}
	@Override
	public void onDestroy() {
		super.onDestroy();
	}
	
	@Override
	public void onDetach() {
		super.onDetach();
	}
}
